//
// Created by firear on 5/25/18.
//

#include "SendHelper.h"
#include "frpc/tcpclient.h"
#include <unistd.h>

#include "frpc/msgstub.h"
#include "publicfun/public.h"

#define LOG_TAG "sendhelper"
#include "publicfun/debug.h"




class TstMsg:public MsgStub{

    int _dealResponse(RpcProtHead * resp) override
    {
        LOGD("%s E", __func__);
        LOGD("%d-%d-%s", resp->mHead.seq, resp->data.size(), resp->data.c_str());
        return 0;
    }

    int _makeRequest() override
    {
        ReadFromFile(mPath.c_str(), data);
        return 0;
    }

public:
    string mPath;
};

void SendHelper::DoSend(const string &destdir)
{
    vector<FileInfo> v;
    EnumFile(destdir.c_str(), v, 1, ENUMFILETYPE_FILE);
    if(!v.empty()){

        for (vector<FileInfo>::iterator i = v.begin(); i != v.end() ; ++i) {
            TcpClient tcpclient;
            tcpclient.connectToServer("192.169.133.22", 9999);
            TstMsg *msg = new TstMsg;
            msg->mPath = i->dirname+i->basename;
            tcpclient.syncCall(msg);
            //TODO
            break;
        }

        //TODO
        //DeleteDirectories(destdir, false);
    }

}
